﻿using ArtMath.Core.Data;
using System;

namespace ArtMath.Component.Manager
{
    [Serializable]
    public class LabelLocationManager
    {
        RectangleD regionRange, currentColRegion;
        public LabelLocationManager()
        {

        }
        public LabelLocationManager(RectangleD regionRange)
        {
            RegionRange = regionRange;
        }
        public RectangleD RegionRange
        {
            get { return regionRange; }
            set
            {
                currentColRegion.Left += value.Left - regionRange.Left;
                currentColRegion.Top += value.Top - regionRange.Top;
                regionRange = value;
            }
        }
        public PointD PutLabel(SizeD labelSize)
        {
            PointD result = currentColRegion.BottomLeft;
            currentColRegion.Height += labelSize.Height;
            if (currentColRegion.Height > RegionRange.Height)
            {
                currentColRegion.Height = labelSize.Height;
                currentColRegion.Left += currentColRegion.Width;
                currentColRegion.Top = RegionRange.Top;
                currentColRegion.Width = labelSize.Width;
                if (currentColRegion.Right > RegionRange.Right)
                {
                    currentColRegion.Left = RegionRange.Left;
                }
            }
            else
            {
                if (labelSize.Width > currentColRegion.Width)
                {
                    currentColRegion.Width = labelSize.Width;
                }
            }
            return result;
        }
    }
}
